<template>
  <div class="components-container">
   
    <div style="height:56px">
      <ul class="toolList">
        <li>
          <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">刷新</el-button>
        </li>
        <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
          <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
        </li>
      </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" :infos="infos" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
   
    <printmodal ref="printPdf"></printmodal>
    <outLibraryMain ref="dialog" @refreshData="getData"></outLibraryMain>
    <outLibraryMainyw ref="dialog_yw" @refreshData="getData"></outLibraryMainyw>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
    margin-left: 0;
}
.btnCenter {
    text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import outLibraryMain from "./outLibraryMain";
import outLibraryMainyw from "./outLibraryMain_yw";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import { DATESELECTMODE } from "@/const/const.js";
import { ORDER } from "@/const/orderConst.js";
import { PRINT } from "@/components/Pdf/PDF.js";
import printmodal from "@/components/Pdf/Print";
import informationRegistrationVue from "../jointPlatform/informationRegistration.vue";

const APPLY = "申请";
const APPLY_YW = "义乌申请";
const MODIFY = "修改";
const MODIFY_YW = "义乌修改";
const DELETE = "删除";
const APPROVAL = "审批";
const NOAPPROVAL = "取消审批";
const GRANT = "发放";
const NOGRANT = "取消发放";
const PRINTING = "打印";
const INFO = "详情";
const INFO_YW = "义乌详情";
const submits = "提交";
const nosubmits = "取消提交";
const allocation = "调拨新增";

const WJZ = "A";
const YJZ = "B";
const YZF = "C";
const YGZ = "D";
const HZ = "E";

export default {
    name: "arehousingManage",
    mixins: [manage],
    data() {
        return {
            DateSelectMode: DATESELECTMODE,
            //查询条件
            selectData: {},
            infos: null,
            selectDataExtend: {
                regDateValue: null
            },
            //收费信息
            chdData: {},
            //付款方式
            payment: [],
            CHDCODNAME: null,
            chlList: [],
            ishsownosubmit: null,
        };
    },
    methods: {
        ruku() {
            this.$refs.dialog.open("入库");
        },
        //获取收费信息
        getData() {
            // let selectData = JSON.parse(JSON.stringify(this.selectData));
            // if (!this.selectData.RegbussnumLike) {
            //   selectData.RegbussnumLike = null;
            // }
            let data = {
                PageIndex: this.pageOrder.currentPage,
                PageSize: this.pageOrder.pageSize,
                OrderBy: this.pageOrder.orderType,
                OrderByType: this.pageOrder.orderSort
                // Data: selectData
            };
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Depot.QueryDpo,
                res => {
                    this.dataList = res.data.content.OutData;
                    this.pageOrder.totalNum = res.data.content.RecordCount;
                }
            );
        },
        //获取表头
        getheaderlist() {
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Column.GetOutLibraryColumns,
                res => {
                    this.headList = res.data.content;
                }
            );
        },
        //功能操作
        operate(order) {
            this.order = order;
            switch (this.order) {
                case APPLY:
                    this.$refs.dialog.open(this.order);
                    break;
                case APPLY_YW:
                    this.$refs.dialog_yw.open(this.order);
                    break;
                case allocation:
                    this.$refs.dialog.open(this.order);
                    break;
                case MODIFY:
                    this.$refs.dialog.open(this.order, this.currentRow.DPOID);
                    break;
                case MODIFY_YW:
                    this.$refs.dialog_yw.open(
                        this.order,
                        this.currentRow.DPOID
                    );
                    break;
                case DELETE:
                    this.deletes();
                    break;
                case INFO:
                    this.$refs.dialog.open(this.order, this.currentRow.DPOID);
                    break;
                case INFO_YW:
                    this.$refs.dialog_yw.open(this.order, this.currentRow.DPOID);
                    break;
                case submits:
                    this.submission();
                    break;
                case nosubmits:
                case NOAPPROVAL:
                case NOGRANT:
                    this.nosubmission();
                    break;
                case APPROVAL:
                    this.approvals();
                    break;
                case GRANT:
                    this.grants();
                    break;
                case PRINTING:
                    this.$refs.printPdf.open(
                        "打印出库明细",
                        this.currentRow.DPOID
                    );
                    break;
                default:
            }
        },
        //出库审核
        approvals() {
            this.$confirm("确认是否审核该物资?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    let data = {
                        DPOID: this.currentRow.DPOID
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Depot.VerifyDpo,
                        res => {
                            this.$message({
                                type: "success",
                                message: "审核成功!"
                            });
                            this.getData();
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
        //出库发放
        grants() {
            this.$confirm("确认是否发放该物资?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    let data = {
                        DPOID: this.currentRow.DPOID
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Depot.GrantDpo,
                        res => {
                            this.$message({
                                type: "success",
                                message: "发放成功!"
                            });
                            this.getData();
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
        //出库提交
        submission() {
            this.$confirm("确认是否提交该数据?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    let data = {
                        DPOID: this.currentRow.DPOID
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Depot.SubmitDpo,
                        res => {
                            this.$message({
                                type: "success",
                                message: "提交成功!"
                            });
                            this.getData();
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
        //取消提交
        nosubmission(){
            this.$confirm("确认是否取消提交该数据?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    let data = {
                        DPOID: this.currentRow.DPOID
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Depot.CancelGrantDpo,  
                        res => {
                            this.$message({
                                type: "success",
                                message: "取消成功成功!"
                            });
                            this.getData();
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
        //删除
        deletes() {
            this.$confirm("确认是否删除该数据?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(callback => {
                    let data = {
                        DPOID: this.currentRow.DPOID
                    };
                    apiBase.DoService(
                        data,
                        apiBase.getApiAdress().Depot.DeleteDpo,
                        res => {
                            this.getData();
                        }
                    );
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        },
        //取消
        cancel() {
            this.$refs.dialog.close();
        },
        GetDpoSubmitToGrant(){
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Param.GetDpoSubmitToGrant,
                res => {
                    this.ishsownosubmit = res.data.content;
                }
            );
        },
        //查询条件重置
        btnRepeat() {
            this.selectData = {};
            this.getData();
        },
        dataRepeat() {
            this.chdData = {};
        },
        GetIdvDetail() {
            let data = {};
            apiBase.DoService(
                data,
                apiBase.getApiAdress().Param.GetIdvDetail,
                res => {
                    this.issendcar = res.data.content; //是否显示保存按钮
                    if (this.issendcar === "10") {
                        this.infos = "详情";
                    } else if (this.issendcar === "20") {
                        this.infos = "义乌详情";
                    }
                }
            );
        },
        //按钮显隐
        // DPOSTATUS
        btnShow(btn) {
            let status = "";
            if (this.currentRow) {
                status = this.currentRow.DPOSTATUS;
            }
            if (btn === APPLY || btn === APPLY_YW) return true;
            if (btn === allocation) return true;
            if (!this.currentRow) return false;
            if (btn === PRINTING) return !(status === "A");
            if (
                btn === submits ||
                btn === MODIFY ||
                btn === DELETE ||
                btn === MODIFY_YW
            )
                return status === "A";
            if (btn === APPROVAL) return status === "B";
            if (btn === GRANT || btn === NOAPPROVAL) return status === "C";
            if (btn === nosubmits){
                if(this.ishsownosubmit === false){
                    return status === "B";
                }else if(this.ishsownosubmit === true){
                    return status === 'D';
                }
                
            } 
            if (btn === NOGRANT) return status === "D";
            // if(btn === APPROVAL) return true;
            // if(btn === GRANT) return true;
            // if(btn === submits && !this.currentRow.DPIDATE) return true;
        }
    },
    components: {
        sweetModal,
        dataTable,
        printmodal,
        outLibraryMain,
        outLibraryMainyw
    },
    activated() {
        this.getData();
    },
    mounted() {
       
    },
    created() {
        this.getheaderlist();
        this.GetDpoSubmitToGrant();
        this.GetIdvDetail();
    },
    watch: {
        "selectDataExtend.regDateValue": function(val) {
            this.selectData.RegdateGreater = null;
            this.selectData.RegDateOrChdDate = null;
            switch (val) {
                case DATESELECTMODE.now:
                    this.selectData.RegDateOrChdDate = formatDate(
                        new Date(),
                        "yyyyMMdd"
                    );
                    break;
                case DATESELECTMODE.future:
                    this.selectData.RegdateGreater = formatDate(
                        new Date(),
                        "yyyyMMdd"
                    );
                    break;
                default:
                    break;
            }
        }
    }
};
</script>

